package cn.wolfcode.web.controller;

import cn.wolfcode.web.domain.Employee;
import cn.wolfcode.web.jsonResult.JsonResult;
import cn.wolfcode.web.mapper.EmployeeMapper;
import cn.wolfcode.web.service.IUpdatePasswordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/Update")
public class UpdateUSerController {
    @Autowired
    private IUpdatePasswordService updatePasswordService;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private HttpSession session;

    @RequestMapping("/UpdatePassword")
    public String UpdatePassword() {
        return "/updateLogin/updatePwd";
    }
    @RequestMapping("/selectPassword")//("/Update/selectPassword.do"
    @ResponseBody
    public JsonResult selectPassword(String oldPassword, String newPassword) {
        try {
            Employee employee = updatePasswordService.selectPassword(oldPassword);
            employee.setPassword(newPassword);

            employeeMapper.updateByPrimaryKey(employee);
            session.setAttribute("employee",employee);

            System.out.println(employee);
           // employeeMapper.
            return  new JsonResult(true,"欢迎登录");
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult(false,"原密码错误");
        }


    }
}
